package top.hkyzf.study.leetcode.string;

import org.junit.Test;

/**
 * @author 朱峰
 * @date 2022-1-18 11:22
 */
public class 统计元音字母序列的数目_1220 {
    public int countVowelPermutation(int n) {
        long mod = 1000000007;
        long [] dp = new long[5];
        long [] ndp = new long[5];
        // 初始化长度为 1 时，分别以 a e i o u 结尾的字符串数量
        // 0 1 2 3 4 分别代表 a e i o u 结尾的字符串数量
        for (int i = 0; i < 5; i++) {
            dp[i] = 1;
        }
        // 动态规划
        for (int i = 2; i <= n; i++) {
            ndp[0] = (dp[1] + dp[2] + dp[4]) % mod;
            ndp[1] = (dp[0] + dp[2]) % mod;
            ndp[2] = (dp[1] + dp[3]) % mod;
            ndp[3] = (dp[2]) % mod;
            ndp[4] = (dp[2] + dp[3]) % mod;
            System.arraycopy(ndp, 0, dp, 0, 5);
        }
        long ans = 0L;
        for (long count : dp) {
            ans = (ans + count) % mod;
        }
        return (int) ans;
    }

    @Test
    public void testCountVowePermutation () {
        int n = 5;
        System.out.println(countVowelPermutation(5));
    }
}
